package com.efruit.subsystemadapters;

import java.util.Collection;
import java.util.Vector;

import com.efruit.externalInterfaces.IShopCart;
import com.efruit.shopcart.ShopCartFacade;
import com.efruit.shopcart.ShoppingItem;
import com.efruit.to.ShopCartTO;

public class ShopCartAdapter implements IShopCart {
	private ShopCartFacade shopCartFacade;
	
	public ShopCartAdapter(){
		shopCartFacade = new ShopCartFacade();
	}

	@Override
	public int addProduct(int id) {
		return shopCartFacade.addProduct(id);
	}

	@Override
	public Vector<ShopCartTO> getShoppingInfo() {
		Collection<ShoppingItem> items = shopCartFacade.getShoppingInfo();
		Vector<ShopCartTO> tos = new Vector<ShopCartTO>(items.size());
		for (ShoppingItem item : items) {
			tos.add(new ShopCartTO(item.getId(), item.getName(), item
					.getAmount(), item.getPrice()));
		}
		return tos;
	}

	@Override
	public void removeProduct(int id) {
		shopCartFacade.removeProduct(id);
	}

	@Override
	public boolean setProductAmount(int id, int amount) {
		return shopCartFacade.setProductAmount(id, amount);
	}

	@Override
	public float getTotal() {
		return shopCartFacade.getTotal();
	}

}
